#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int n;
    string tmp;
    vector<string> ans;
    void dfs(int x, string &s)
    {
        if (n == x)
        {
            ans.emplace_back(tmp);
            return;
        }
        // 不改
        tmp[x] = s[x];
        dfs(x + 1, s);

        // 改
        if (((tmp[x] >= 'A') && (tmp[x] <= 'Z')) || ((tmp[x] >= 'a') && (tmp[x] <= 'z')))
        {
            if ((tmp[x] >= 'A') && (tmp[x] <= 'Z'))
            {
                tmp[x] += 32;
            }
            else if ((tmp[x] >= 'a') && (tmp[x] <= 'z'))
            {
                tmp[x] -= 32;
            }
            dfs(x + 1, s);
        }
    }
    vector<string> letterCasePermutation(string s)
    {
        n = s.size();
        tmp.resize(n);
        dfs(0, s);
        return ans;
    }
};

class Solution
{
public:
    int n;
    string tmp;
    vector<string> ans;

    void dfs(int x, string &s)
    {
        if (n == x)
        {
            ans.emplace_back(tmp);
            return;
        }
        // 不改变当前字符
        tmp[x] = s[x];
        dfs(x + 1, s);

        // 如果当前字符是字母，改变其大小写
        if (isalpha(s[x]))
        {
            if (isupper(s[x]))
            {
                tmp[x] = tolower(s[x]);
            }
            else
            {
                tmp[x] = toupper(s[x]);
            }
            dfs(x + 1, s);
        }
    }

    vector<string> letterCasePermutation(string s)
    {
        n = s.size();
        tmp.resize(n);
        dfs(0, s);
        return ans;
    }
};
int main()
{
    Solution s1;
    string s = "a1b2";
    vector<string> res = s1.letterCasePermutation(s);
    for (auto &t : res)
    {
        cout << t << endl;
    }
    return 0;
}
